package itheima.springbootwebdemo.web;

import itheima.springbootwebdemo.Service.EmpService;
import itheima.springbootwebdemo.Service.EmpServiceA;
import itheima.springbootwebdemo.pojo.Emp;
import itheima.springbootwebdemo.pojo.Result;
import itheima.springbootwebdemo.utils.XmlParserUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class EmpController {
    /*@RequestMapping("/listEmp")
    public Result list(){
        String file = this.getClass().getClassLoader().getResource("emp.xml").getFile();

        List<Emp> emps = XmlParserUtils.parse(file, Emp.class);

        emps.forEach(emp -> {
            if(emp.getGender().equals("1")){
                emp.setGender("男");
            }else{
                emp.setGender("女");
            }
            if(emp.getJob().equals("1")){
                emp.setJob("讲师");
            }else if (emp.getJob().equals("2")){
                emp.setJob("班主任");
            }else {
                emp.setJob("就业指导");
            }
        });

        return Result.success(emps);*/
    @Autowired
    //业务层对象
    private EmpService empService;

    @RequestMapping("/listEmp")
    public Result list() {
        //1. 调用service层, 获取数据
        List<Emp> empList = empService.listEmp();

        //3. 响应数据
        return Result.success(empList);
    }
}
